home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 / Ham Radio 2000.iso / ham2000 / misc / rtty12g / ru.c < prev    next >
Text File  |  1986-10-02  |  7KB  |  317 lines

  1. /*********************************************************************/
  2. /*                                     */
  3. /* RTTY ART UTILITY PROGRAM FOR THE IBM PERSONAL COMPUTER         */
  4. /*   Companion program to the RTTY program for the IBM PC         */
  5. /*                                     */
  6. /* BY    GLENN E. WELMAN  -  KF4NB                     */
  7. /*    3301 PASTERN CT.                         */
  8. /*    LEXINGTON, KY 40513                         */
  9. /*                                     */
  10. /*  (C) COPYRIGHT WELMAN SOFTWARE 1986                     */
  11. /*********************************************************************/
  12. /*                                     */
  13. /* Rules for distribution of this program:                 */
  14. /*                                     */
  15. /*  FEEL FREE TO GIVE COPIES OF THIS PROGRAM TO YOUR FRIENDS.         */
  16. /*                                     */
  17. /*  PLEASE, DON'T SELL OR BARTER THE PROGRAM TO OTHERS.              */
  18. /*                                     */
  19. /*  IF YOU FIND BUGS IN THE PROGRAM, FEEL FREE TO             */
  20. /*  CORRESPOND DIRECTLY WITH ME. (SASE REQUESTED)             */
  21. /*                                     */
  22. /*  WHEN YOU PASS ALONG THE PROGRAM, INCLUDE ONLY THE             */
  23. /*  ORIGINAL UNMODIFIED VERSION.                     */
  24. /*                                     */
  25. /*  DO NOT REMOVE THESE GUIDELINES FROM THE PROGRAM             */
  26. /*  OR DOCUMENT.                             */
  27. /*                                     */
  28. /*                                     */
  29. /*             73's                                        */
  30. /*             Glenn - KF4NB                     */
  31. /*                                     */
  32. /*********************************************************************/
  33.  
  34.  
  35. #include <fcntl.h>
  36. #include <sys\types.h>
  37. #include <sys\stat.h>
  38. #include <dos.h>
  39. #include <io.h>
  40. #include <stdio.h>
  41. #include <stdlib.h>
  42. #undef toupper
  43. #undef tolower
  44.  
  45.     int in,out,rcnt,first;
  46.     int prt,newfile,comp;
  47.  
  48. main()
  49. {
  50.     char infile[60];
  51.     char outfile[60];
  52.     char temp[10];
  53.     int cnt,tcnt;
  54.     unsigned char ch,lch,tmp;
  55.  
  56. /* Print the program header */
  57.  
  58.     setmode (fileno(stdout),O_BINARY);
  59.     cls ();
  60.     printf("\nThe RTTY Art Utility Program");
  61.     printf("\r\nby Glenn Welman, KF4NB");
  62.     printf("\r\n(C) Copyright Welman Software 1986");
  63.     temp[0] = '\0';
  64.  
  65. do
  66. {
  67.     if (toupper(temp[0]) == 'Y')
  68.     cls ();
  69.     rcnt=0;
  70.     first=0;
  71.  
  72. /* Get the input file and make sure it is good */
  73.  
  74.     printf("\r\n\nEnter the name of the file to process? ");
  75.     gets(infile);
  76.  
  77.     if (infile[0] == '\0')
  78.     break;
  79.  
  80.     in=open(infile,O_RDONLY | O_BINARY);
  81.     if(in == -1)
  82.     {
  83.     perror("\nCannot open ");
  84.     printf("filename is %s",infile);
  85.     abort ();
  86.     }
  87.  
  88. /* Check to see if they want the data saved in a file */
  89.  
  90.     printf("\nWould you like to save the results (y/n)? ");
  91.     gets(temp);
  92.  
  93.     if (toupper(temp[0]) == 'Y')
  94.     {
  95.  
  96. /* Get the name of the file where they want the data saved */
  97.  
  98.     printf("\nEnter the name of the new file? ");
  99.     gets(outfile);
  100.  
  101.     if (outfile[0] != '\0')
  102.         {
  103.         newfile=-1;
  104.  
  105.         out=open(outfile,O_WRONLY | O_TRUNC | O_CREAT | O_BINARY,S_IWRITE);
  106.         if(out == -1)
  107.         {
  108.         perror("\nCannot open ");
  109.         printf("filename is %s",outfile);
  110.         abort ();
  111.         }
  112.  
  113.  
  114. /* See if they want the data compressed */
  115.  
  116.         printf("\nWould you like to compress the file (y/n)? ");
  117.         gets(temp);
  118.  
  119.         if (toupper(temp[0]) == 'Y')
  120.         comp=-1;
  121.         else
  122.         comp=0;
  123.         }
  124.     }
  125.  
  126.     else
  127.     newfile=0;
  128.  
  129. /* Check to see if they want the data printed */
  130.  
  131.     printf("\nWould you like to print the file (y/n)? ");
  132.     gets(temp);
  133.  
  134.     if (toupper(temp[0]) == 'Y')
  135.     {
  136.     prt=-1;
  137.     setmode (fileno(stdprn),O_BINARY);
  138.     fflush(stdprn);
  139.     setbuf(stdprn,NULL);
  140.  
  141. /* Check to see if they want small or regular size printing */
  142.  
  143.     printf("\nWould you like small or full size print (default=small) (s/f)? ");
  144.     gets(temp);
  145.  
  146.     if (toupper(temp[0]) == 'F')
  147.         fputs("\x12\x1b\x32",stdprn);
  148.     else
  149.         fputs("\x0f\x1b\x31",stdprn);
  150.  
  151.     }
  152.     else
  153.     prt=0;
  154.  
  155.  
  156. /* Read the input file in it's entirety */
  157.  
  158.     cls ();
  159.     lch = 0;
  160.     while(!eof(in))
  161.     {
  162.     read(in,&ch,1);
  163.     switch (ch)
  164.     {
  165.     case 255:
  166.         read(in,&ch,1);
  167.         tcnt = ch;
  168.         read(in,&ch,1);
  169.         for (cnt=0;cnt < tcnt;cnt++)
  170.         process(ch);
  171.         break;
  172.     case '\x14':
  173.     case '\x17':
  174.         process(ch-10);
  175.         break;
  176.     case '\x0a':
  177.     case '\x0d':
  178.         if ((lch != 20) && (lch != 23))
  179.         process(ch);
  180.         else
  181.         ch = lch;
  182.         break;
  183.     case '\x1a':
  184.         ch = lch;
  185.         break;
  186.     default:
  187.         process(ch);
  188.         break;
  189.     }
  190.     lch = ch;
  191.     }
  192.     if (newfile && ((lch == 10) || (lch == 13) || (lch == 20) || (lch == 23)))
  193.     {
  194.     tmp = 0x0d;
  195.     write(out,&tmp,1);
  196.     tmp = 0x0a;
  197.     write(out,&tmp,1);
  198.     }
  199.  
  200.     tmp = 0x1a;     /* write end of file for BASIC compatibility */
  201.     write(out,&tmp,1);
  202.  
  203.     close(in);
  204.     if (newfile) close(out);
  205.  
  206.     printf("\nWould you like to process another file (y/n)? ");
  207.     gets(temp);
  208.  
  209. } while(toupper(temp[0]) == 'Y');
  210.  
  211. }
  212.  
  213. /* Process the characters, send to file and/or printer as requested */
  214.  
  215. process (ch)
  216.  
  217.     unsigned char ch;
  218.  
  219. /* put the character on the screen */
  220. {
  221.     static unsigned char last,lastin=0;
  222.     unsigned char tmp,spc=255;
  223.  
  224.     if (ch != '\7') putchar(ch);
  225.  
  226. /* send the character to the printer, if requested */
  227.  
  228.     if ((prt) && (ch != '\7')) putc(ch,stdprn);
  229.  
  230. /* send the character to the file, if requested */
  231.  
  232.     if (newfile)
  233.     {
  234.     if ((first != 0) && (ch != 10) && (ch != 13) && ((lastin == 10) || (lastin == 13)))
  235.         {
  236.         tmp = 0x0d;
  237.         write(out,&tmp,1);
  238.         tmp = 0x0a;
  239.         write(out,&tmp,1);
  240.         }
  241.     if (comp)
  242.         {
  243.         if (ch == lastin)
  244.         rcnt++;
  245.         else
  246.         {
  247.         if ((lastin != 10) && (lastin != 13))
  248.             switch (rcnt)
  249.             {
  250.             case 0:
  251.             break;
  252.             case 1:
  253.             write(out,&last,1);
  254.             break;
  255.             case 2:
  256.             write(out,&last,1);
  257.             write(out,&last,1);
  258.             break;
  259.             case 26:
  260.             write(out,&last,1);
  261.             rcnt--;
  262.             default:
  263.             write(out,&spc,1);
  264.             write(out,&rcnt,1);
  265.             write(out,&last,1);
  266.             break;
  267.             }
  268.         last = ch;
  269.         rcnt = 1;
  270.         }
  271.         }
  272.     else if ((ch != 10) && (ch != 13))
  273.         write(out,&ch,1);
  274.  
  275.     if ((ch == 10) || (ch == 13))
  276.         {
  277.         tmp = ch+10;
  278.         write(out,&tmp,1);
  279.         }
  280.     lastin = ch;
  281.     }
  282.     first = 1;
  283.     return;
  284. }
  285.  
  286. cls ()
  287. {
  288. #define CRT_BIOS 0x10
  289. union REGS inregs, outregs;
  290. unsigned int page;
  291. unsigned int cols;
  292.  
  293. inregs.h.ah = 15;    /* get active page and screen size */
  294.  
  295. int86(CRT_BIOS, &inregs, &outregs);
  296.  
  297. page = outregs.h.bh;
  298. cols = outregs.h.ah;
  299.  
  300. inregs.h.al = 0;
  301. inregs.h.ch = 0;
  302. inregs.h.cl = 0;
  303. inregs.h.dh = 24;
  304. inregs.h.dl = cols;
  305. inregs.h.bh = 7;
  306. inregs.h.ah = 6;    /* scroll up command */
  307.  
  308. int86(CRT_BIOS, &inregs, &outregs);
  309.  
  310. inregs.h.bh = page;
  311. inregs.h.dh = 0;
  312. inregs.h.dl = 0;
  313. inregs.h.ah = 2;    /* locate cursor at upper left corner */
  314.  
  315. int86(CRT_BIOS, &inregs, &outregs);
  316. }
  317.